package com.logistics.admin;

import java.io.File;

import net.sf.json.JSONObject;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("imageUpAction")
@Scope("prototype")
public class ImageUpAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6154026354937573285L;

	private File upfile;
	/**
	 * upfile
	 *
	 * @return
	 */
	public File getUpfile() {
		return upfile;
	}

	/**
	 * upfile
	 *
	 * @param upfile
	 */
	public void setUpfile(File upfile) {
		this.upfile = upfile;
	}

	private String upfileFileName;
	/**
	 * 上传文件名
	 *
	 * @return
	 */
	public String getUpfileFileName() {
		return upfileFileName;
	}

	/**
	 * 上传文件名
	 *
	 * @param upfileFileName
	 */
	public void setUpfileFileName(String upfileFileName) {
		this.upfileFileName = upfileFileName;
	}

	private String upfileContentType;

	/**
	 * upfileContentType
	 *
	 * @return
	 */
	public String getUpfileContentType() {
		return upfileContentType;
	}

	/**
	 * upfileContentType
	 *
	 * @param upfileContentType
	 */
	public void setUpfileContentType(String upfileContentType) {
		this.upfileContentType = upfileContentType;
	}

	
	private String param1;
	
	/**
	 * param1
	 *
	 * @return
	 */
	public String getParam1() {
		return param1;
	}

	/**
	 * param1
	 *
	 * @param param1
	 */
	public void setParam1(String param1) {
		this.param1 = param1;
	}

	private String param2;
	/**
	 * param2
	 *
	 * @return
	 */
	public String getParam2() {
		return param2;
	}

	/**
	 * param2
	 *
	 * @param param2
	 */
	public void setParam2(String param2) {
		this.param2 = param2;
	}

	private String pictitle;
	
	/**
	 * pictitle
	 *
	 * @return
	 */
	public String getPictitle() {
		return pictitle;
	}

	/**
	 * pictitle
	 *
	 * @param pictitle
	 */
	public void setPictitle(String pictitle) {
		this.pictitle = pictitle;
	}
		
	public void uploaderImage(){
		
		try {
			UploaderImage uploaderImage = new UploaderImage(getRequest());
			uploaderImage.upload(upfile, upfileFileName, getUeditorImageUploadFolder(), pictitle);
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("original", uploaderImage.getOriginalName());
			jsonObject.put("url", uploaderImage.getUri());
			jsonObject.put("title", uploaderImage.getTitle());
			jsonObject.put("state", uploaderImage.getState());

			outputJsonObject(jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
